import os

#
TotalTRows = 30000
rowPerFile = 10000

PORT = 65535
IP = 200
#
num = 0


def genJson(fileName):
    global num

    with open(fileName, 'w') as f:
        for ip1 in range(IP):
            for ip2 in range(IP):
                for port in range(1, PORT):
                    num = num + 1
                    f.writelines(
                        '{"index":{"_index":"aggt","_id":%d}}\n' % (num))
                    f.writelines(
                        '{"clientip":"10.10.%d.%d", "port":%d, "sql":"中国北京市海淀区", "tm": "2020-11-01 10:00:00"}\n' % (ip1, ip2, port))

                    if 0 == num % rowPerFile:
                        return


if __name__ == "__main__":
    print('generate...')
    i = 0
    while num < TotalTRows:
        genJson("esdata/aa%d.json" % (i))
        i = i + 1
        print("rows: %d" % num) 
